<template>
	<view class="cantainer">
		<!-- 已登录 -->
		<view class="top-image"></view>
		<!-- 适配苹果X顶部 -->
		<view :style="'height:' + topBarTop() + 'px;'"></view>
		<view v-if="token">
			<view class="top-left" @click="showstroe">
				<view>{{ storeName }}</view>
				<image src="../../static/images/qiyehuan.png" mode=""></image>
			</view>
		</view>
		<view v-if="showType == 1">
			<!-- 今日订单 -->
			<view class="today-order">
				<view>{{ todayOrderNum }}</view>
				<view>今日订单</view>
			</view>
			<!-- 订单titile -->
			<view class="min-info">
				<view>
					<text>{{ completeOrdeNum }}</text>
					<text>已完成</text>
				</view>
				<view>
					<text>{{ paySuccessOrderNum }}</text>
					<text>支付成功</text>
				</view>
				<view>
					<text>{{ CanceOrderNum }}</text>
					<text>已取消</text>
				</view>
			</view>
			<!-- 订单列表 -->
			<view class="order" v-if="showType == 1">
				<view class="title">全部订单</view>
				<view class="order-item" v-for="(item, index) in orderList" :key="item.id">
					<image class="left-image" :src="item.room_image" mode=""></image>
					<view class="right-info">
						<view class="order-title">
							<view>{{ item.store_name }}</view>
							<view>{{ item.status_str }}</view>
						</view>
						<view class="time-price">
							<view>开始时间：{{ item.start_time }}</view>
							<view>¥{{ item.price }}</view>
						</view>
						<view class="room">茶市：{{ item.room_name }}</view>
					</view>
				</view>
				<uni-load-more :status="status" showIcon="true" />
			</view>
		</view>
		<!-- 未登录 -->
		<view class="weilogin" v-if="!token">
			<image src="../../static/images/weilogin.png" mode=""></image>
			<view>您暂未登录,请先登录~</view>
			<button style="background-color: #45bb52;width: 240rpx;color: #FFF;" @click="goLogin()">登录</button>
		</view>
		<!-- 没有权限 -->
		<view class="weiquanxian" v-if="showType == 2 || showType == 3">
			<image src="../../static/images/weilogin.png" mode=""></image>
			<view>不好意思，您暂无权限～</view>
		</view>
		<u-picker :show="showStroe" :columns="storeList" keyName="name" @confirm="selectItem" @cancel="showStroe = false"></u-picker>
	</view>
</template>
<script>
export default {
	data() {
		return {
			showStroe: false,
			showType: uni.getStorageSync('userinfo').type ? uni.getStorageSync('userinfo').type : '',
			page: 1,
			last_page: 0,
			token: uni.getStorageSync('token') ? uni.getStorageSync('token') : '',
			// storeId: uni.getStorageSync('storeList')[0].id ? uni.getStorageSync('storeList')[0].id : '',
			storeId: '',
			orderList: [],
			// 今日订单
			todayOrderNum: 0,
			// 已取消订单
			CanceOrderNum: 0,
			// 支付成功订单
			paySuccessOrderNum: 0,
			// 已完成订单
			completeOrdeNum: 0,
			storeList: [uni.getStorageSync('storeList')],
			storeName: '软程科技',
			status: 'more'
		};
	},
	onLoad() {
		this.showType = uni.getStorageSync('userinfo').type ? uni.getStorageSync('userinfo').type : '';
		this.token = uni.getStorageSync('token') ? uni.getStorageSync('token') : '';
		console.log(this.token, 'token', this.showType);

		this.storeId = uni.getStorageSync('storeList')[0].id ? uni.getStorageSync('storeList')[0].id : '';
		// 管理员权限
		if (this.showType == 1) {
			// 获取订单列表
			this.getOrderList();
			// 初始化订单数量
			this.getOrderInit();
			// 获取登录成功后的商铺name
		}

		if (uni.getStorageSync('storeList')[0].name != '') {
			this.storeName = uni.getStorageSync('storeList')[0].name;
		}
	},
	onReachBottom() {
		this.status = 'noMore';
		if (this.page < this.last_page) {
			this.status = 'more';
			this.page += 1;
			this.getOrderList();
		}
	},
	methods: {
		showstroe() {
			if (this.showType == 2 || this.showType == 3) {
				uni.showToast({
					title: '暂无权限',
					icon: 'none'
				});
				return;
			}
			this.showStroe = true;
		},
		selectItem(e) {
			this.storeId = e.value[0].id;
			uni.setStorageSync('storeListId', [e.value[0].id]);
			this.storeName = e.value[0].name;
			this.showStroe = false;
			this.page = 1;
			this.getOrderList();
			// 初始化订单数量
			this.getOrderInit();
		},
		goLogin() {
			uni.navigateTo({
				url: '../login/login'
			});
		},
		getOrderList() {
			this.https('/order/orderList', {
				page: this.page,
				store_id: this.storeId
			}).then(res => {
				this.last_page = res.data.last_page;
				if (this.page == 1) {
					this.orderList = res.data.data;
				} else {
					this.orderList = this.orderList.concat(res.data.data);
				}
			});
		},
		getOrderInit() {
			// 获取今日订单
			this.getTodayOrderNum();
			// 获取已取消订单
			this.getCanceOrderNum();
			// 获取支付成功订单
			this.getPaySuccessOrderNum();
			// 获取已完成订单
			this.getCompleteOrdeNum();
		},
		// 今日订单
		getTodayOrderNum() {
			this.https('/order/todayOrder', {
				store_id: this.storeId
			}).then(res => {
				this.todayOrderNum = res.data;
			});
		},
		// 已取消订单
		getCanceOrderNum() {
			this.https('/order/cancelOrder', {
				store_id: this.storeId
			}).then(res => {
				this.CanceOrderNum = res.data;
			});
		},
		// 支付成功订单
		getPaySuccessOrderNum() {
			this.https('/order/payOrder', {
				store_id: this.storeId
			}).then(res => {
				console.log(res);
				this.paySuccessOrderNum = res.data;
			});
		},
		// 支付已完成订单
		getCompleteOrdeNum() {
			this.https('/order/completeOrder', {
				store_id: this.storeId
			}).then(res => {
				this.completeOrdeNum = res.data;
			});
		}
	}
};
</script>
<style lang="scss">
.weilogin {
	width: 474rpx;
	height: 800rpx;
	margin: 0 auto;
	margin-top: -100rpx;
	display: flex;
	flex-direction: column;
	align-items: center;

	image {
		width: 474rpx;
		height: 474rpx;
	}

	view {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
		margin: 40rpx 0;
	}
}

.weiquanxian {
	width: 474rpx;
	height: 800rpx;
	margin: 0 auto;
	margin-top: -100rpx;
	display: flex;
	flex-direction: column;
	align-items: center;

	image {
		width: 474rpx;
		height: 474rpx;
	}

	view {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
		margin: 40rpx 0;
	}
}

page {
	background-color: #f0f2f5;
}

.cantainer {
	background-size: 750rpx 504rpx;
}

.top-image {
	width: 750rpx;
	height: 504rpx;
	position: relative;
	background-color: #45bb52;
}

.top-left {
	position: absolute;
	top: 90rpx;
	left: 40rpx;
	height: 64rpx;
	border-radius: 24rpx;
	border: 2rpx solid #ffffff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 20rpx;
	color: #ffffff;
}
.top-left view {
	overflow: hidden;
	text-overflow: ellipsis;
	height: 50rpx;
	margin-right: 20rpx;
	min-width: 150rpx;
}

.top-left image {
	width: 32rpx;
	height: 32rpx;
}

.today-order {
	display: flex;
	flex-direction: column;
	width: 200rpx;
	height: 150rpx;
	justify-content: space-between;
	align-items: center;
	position: absolute;
	z-index: 5;
	top: 200rpx;
	left: 280rpx;
}

.today-order view:nth-child(1) {
	font-size: 80rpx;
	font-family: DINAlternate-Bold, DINAlternate;
	font-weight: bold;
	color: #fff;
}

.today-order view:nth-child(2) {
	font-size: 28rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 500;
	color: #ffffff;
}

.min-info {
	width: 670rpx;
	height: 200rpx;
	background-color: #fff;
	box-shadow: 0px 0px 12rpx 0px rgba(189, 189, 189, 0.5);
	border-radius: 40rpx;
	display: flex;
	align-items: center;
	justify-content: space-around;
	position: absolute;
	top: 400rpx;
	left: 40rpx;
}

.min-info view {
	display: flex;
	justify-content: center;
	flex-direction: column;
	align-items: center;
	justify-content: space-between;
	height: 150rpx;
}

.min-info view text:nth-child(1) {
	font-size: 60rpx;
	font-family: PingFangSC-Semibold, PingFang SC;
	font-weight: 600;
	color: #000000;
}

.min-info view text:nth-child(2) {
	width: 112rpx;
	height: 40rpx;
	font-size: 28rpx;
	font-family: PingFangSC-Semibold, PingFang SC;
	font-weight: 600;
	color: #999999;
	text-align: center;
}

.order {
	width: 670rpx;
	margin: 0 auto;
	margin-top: 40rpx;
	padding-bottom: 40rpx;
}

.order .title {
	font-weight: 500;
	color: #000000;
	margin-bottom: 60rpx;
}

.order-item {
	width: 670rpx;
	height: 200rpx;
	box-shadow: 0px 0px 12rpx 0rpx rgba(189, 189, 189, 0.5);
	border-radius: 20rpx;
	background-color: #fff;
	display: flex;
	align-items: center;
	justify-content: space-around;
	margin-bottom: 20rpx;

	.order-title,
	.time-price {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.order-title {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 50rpx;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.time-price {
		font-size: 24rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;

		view:nth-child(2) {
			color: #000;
			font-size: 28rpx;
		}
	}

	.room {
		font-size: 24rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.order-title {
		view:nth-child(1) {
			width: 280rpx;
			height: 44rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 700;
			color: #000000;
		}

		view:nth-child(2) {
			color: #45bb52;
			font-size: 28rpx;
		}
	}
}

.right-info {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	width: 450rpx;
	height: 140rpx;
}

.order-item .left-image {
	width: 160rpx;
	height: 160rpx;
}
</style>
